package ar.com.notarip.bb.infosubte.util;

import net.rim.device.api.ui.Adjustment;
import net.rim.device.api.ui.AdjustmentListener;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.component.TextSpinBoxField;

public  class MySpinBoxField extends TextSpinBoxField implements FieldChangeListener
{           
    private static final int WIDTH = 45;
    
    private Adjustment _adjustment;
    
    /**
     * Creates a new MySpinBoxField object
     * @param choices An array of Integers representing the values which can be selected by this field
     */
    public MySpinBoxField(Integer[] choices)
    {
        super(choices);
        _adjustment = new Adjustment(0, 0, choices.length, 0, 0, 0);            
        setChangeListener(this);
    }
     
    
    /**
     * @see FieldChangeListener#fieldChanged(Field, int)
     */
    public void fieldChanged(Field field, int context)
    {
        _adjustment.setValue(getSelectedIndex());            
    }     
    
     
    /**
     * Return the adjustment object associated with this field
     * @return The adjustment associated with this field
     */
    Adjustment getAdjustment()
    {
        return _adjustment;
    }    
    
    
    /**
     * Adds a listener which will be informed of changes via the Adjustment object
     * @param listener The new listener
     */
    void setListener(AdjustmentListener listener)
    {
        _adjustment.addListener(listener);
    }  
    
    
    /**
    * @see Field#getPreferredWidth()
    */
    public int getPreferredWidth()
    {
        return WIDTH;
    }
    

    
}